package com.spic.business.train.year.service.impl;

import com.spic.business.train.year.domain.TrainPlanYearSearchRecord;
import com.spic.business.train.year.mapper.TrainPlanYearSearchRecordMapper;
import com.spic.business.train.year.service.ITrainPlanYearSearchRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 年度计划搜索记录框Service业务层处理
 *
 * @author yangjie
 * @date 2021-11-24
 */
@Service
public class TrainPlanYearSearchRecordServiceImpl implements ITrainPlanYearSearchRecordService
{
    @Autowired
    private TrainPlanYearSearchRecordMapper trainPlanYearSearchRecordMapper;

    /**
     * 查询年度计划搜索记录框
     *
     * @param id 年度计划搜索记录框主键
     * @return 年度计划搜索记录框
     */
    @Override
    public TrainPlanYearSearchRecord selectTrainPlanYearSearchRecordById(String id)
    {
        return trainPlanYearSearchRecordMapper.selectTrainPlanYearSearchRecordById(id);
    }

    /**
     * 查询年度计划搜索记录框列表
     *
     * @param trainPlanYearSearchRecord 年度计划搜索记录框
     * @return 年度计划搜索记录框
     */
    @Override
    public List<TrainPlanYearSearchRecord> selectTrainPlanYearSearchRecordList(TrainPlanYearSearchRecord trainPlanYearSearchRecord)
    {
        return trainPlanYearSearchRecordMapper.selectTrainPlanYearSearchRecordList(trainPlanYearSearchRecord);
    }
    //查询 // 类型: 1培训机构 2培训地点 3培训对象
    @Override
    public Map<String, Object> selectTrainPlanYearSearchRecordMap( Long deptId)
    {
        // 类型: 1培训机构 2培训地点 3培训对象
        Map<String, Object> map = new HashMap<>();
        TrainPlanYearSearchRecord trainPlanYearSearchRecord = new TrainPlanYearSearchRecord();
        trainPlanYearSearchRecord.setType("1");
        trainPlanYearSearchRecord.setDeptId(deptId);
        List<TrainPlanYearSearchRecord> trainPlace = trainPlanYearSearchRecordMapper.selectTrainPlanYearSearchRecordList(trainPlanYearSearchRecord);
        trainPlanYearSearchRecord.setType("2");
        List<TrainPlanYearSearchRecord> trainOrg = trainPlanYearSearchRecordMapper.selectTrainPlanYearSearchRecordList(trainPlanYearSearchRecord);
        trainPlanYearSearchRecord.setType("3");
        List<TrainPlanYearSearchRecord> trainPersoneel = trainPlanYearSearchRecordMapper.selectTrainPlanYearSearchRecordList(trainPlanYearSearchRecord);

        map.put("trainPlace",trainPlace);
        map.put("trainOrg",trainOrg);
        map.put("trainPersoneel",trainPersoneel);
        return map;
    }

    /**
     * 新增年度计划搜索记录框
     *
     * @param trainPlanYearSearchRecord 年度计划搜索记录框
     * @return 结果
     */
    @Override
    public int insertTrainPlanYearSearchRecord(TrainPlanYearSearchRecord trainPlanYearSearchRecord)
    {

        if(trainPlanYearSearchRecord!=null){
            List<TrainPlanYearSearchRecord> trainPlanYearSearchRecords = trainPlanYearSearchRecordMapper.selectTrainPlanYearSearchRecordList(trainPlanYearSearchRecord);
            if(trainPlanYearSearchRecords!=null && trainPlanYearSearchRecords.size()>0){
                return 0;
            }
        }
        int count = trainPlanYearSearchRecordMapper.insertTrainPlanYearSearchRecord(trainPlanYearSearchRecord);
        return count;
    }

    /**
     * 修改年度计划搜索记录框
     *
     * @param trainPlanYearSearchRecord 年度计划搜索记录框
     * @return 结果
     */
    @Override
    public int updateTrainPlanYearSearchRecord(TrainPlanYearSearchRecord trainPlanYearSearchRecord)
    {
        return trainPlanYearSearchRecordMapper.updateTrainPlanYearSearchRecord(trainPlanYearSearchRecord);
    }

    /**
     * 批量删除年度计划搜索记录框
     *
     * @param ids 需要删除的年度计划搜索记录框主键
     * @return 结果
     */
    @Override
    public int deleteTrainPlanYearSearchRecordByIds(Long[] ids)
    {
        return trainPlanYearSearchRecordMapper.deleteTrainPlanYearSearchRecordByIds(ids);
    }

    /**
     * 删除年度计划搜索记录框信息
     *
     * @param id 年度计划搜索记录框主键
     * @return 结果
     */
    @Override
    public int deleteTrainPlanYearSearchRecordById(Long id)
    {
        return trainPlanYearSearchRecordMapper.deleteTrainPlanYearSearchRecordById(id);
    }
}
